package self.niu.com.resume.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import java.lang.ref.PhantomReference;
import java.util.ArrayList;
import java.util.List;

import self.niu.com.resume.R;
import self.niu.com.resume.activity.YuWeiActivity;
import self.niu.com.resume.db.dbHeple.DbHander;
import self.niu.com.resume.ui.MyUtils;

/**
 * A simple {@link Fragment} subclass.
 */
public class ProjectFragment extends Fragment implements AdapterView.OnItemClickListener {
    private View view;
    private List<String> list;
    @ViewInject(R.id.project_show_lv)
    private ListView listview;
    private ArrayAdapter adapter;

    public ProjectFragment() {
        // Required empty public constructor
    }

    public static ProjectFragment getInstance() {
        return new ProjectFragment();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        view = inflater.inflate(R.layout.fragment_project, container, false);
        ViewUtils.inject(this, view);
        setDataDb();
        initView();
        return view;
    }


    private void initView() {
        list = new ArrayList<>();
        list.add("项目-余味美食");
        list.add("项目-贵州美食网");
        list.add("项目-美呀");
        list.add("项目-游记");
        adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_spinner_dropdown_item, list);
        listview.setAdapter(adapter);
        listview.setOnItemClickListener(this);
    }

    //添加数据
    private void setDataDb() {
        for (int i = 0; i < 4; i++) {
            DbHander.getInstance().addProjects(
                    MyUtils.projectsName[i],
                    MyUtils.projectsTime[i],
                    MyUtils.projectsTool[i],
                    MyUtils.projectsSummary[i],
                    MyUtils.projectsDuty[i],
                    MyUtils.projectsTechnic[i],
                    "" + i
            );
        }
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        startActivity(new Intent(getActivity(), YuWeiActivity.class).putExtra("type",position));
    }
}
